package servlet;

import pojo.School;
import pojo.Student;
import pojo.Subject;
import pojo.Teacher;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 10-OGNL使用
 */
@WebServlet("/demo07")
public class Demo07Servlet extends ViewBaseServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Student student = new Student();

        student.setStudentName("樊育东");


        student.setSubject(new Subject("java"));

        List<School> schoolList = new ArrayList<>();
        schoolList.add(new School("尚大幼儿园"));
        schoolList.add(new School("尚大小学"));
        schoolList.add(new School("尚大中学"));
        schoolList.add(new School("尚大大学"));
        student.setSchoolList(schoolList);

        Map<String, Teacher> teacherMap = new HashMap<>();
        teacherMap.put("t1", new Teacher("xiaoqiu"));
        teacherMap.put("t2", new Teacher("oldqiu"));
        student.setTeacherMap(teacherMap);

        request.setAttribute("student", student);
        processTemplate("demo07", request, response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
